blob: 815387f157c037e8bc4f216deae046be0733cdf9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
---
import locales from '$i18n/locales';
import Article from '$layouts/Article.astro';
import type Locale from '$types/Locale';
import { CollectionEntry, getCollection } from 'astro:content';
export async function getStaticPaths() {
function localeFromSlug(slug: CollectionEntry<'news'>['slug']): Locale | undefined {
const lowerCaseLocale = new RegExp(`^(${locales.map((l) => l.toLocaleLowerCase()).join('|')})`);
const matchedLowerCaseLocale = slug.match(lowerCaseLocale)?.[1];
switch (matchedLowerCaseLocale) {
case 'sco':
return 'sco';
case 'en-gb':
return 'en-GB';
default:
console.warn('Could not find locale in slug %s', slug);
return undefined;
}
}
const paths = (await getCollection('news')).map((entry) => ({
params: {
slug: entry.slug.replace('/', '-'),
locale: localeFromSlug(entry.slug),
},
props: { entry },
}));
console.info('Paths: %s', JSON.stringify(paths));
return paths;
}
const { entry } = Astro.props;
const { Content } = await entry.render();
---
<Article title={entry.data.title}>
<section>
<h1>{entry.data.title}</h1>
<Content />
</section>
</Article>
|